{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "from pocketflow import Node, Flow\n",
    "from utils import call_llm"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [],
   "source": [
    "class structure_node(Node):\n",
    "    def prep(self, shared):\n",
    "        if \"text\" not in shared:\n",
    "            return None\n",
    "        return shared[\"text\"]\n",
    "    def exec(self, text):\n",
    "        prompt = f\"\"\"\n",
    "        你是一个专业的数据分析师，现在需要你将以下文本中的数据结构提取出来，请严格遵循以下要求：\n",
    "        1. 提取出数据结构\n",
    "        2. 确保数据结构正确\n",
    "        3. 确保数据结构符合要求\n",
    "        4. 仅提取出数据结构，不要输出任何其他内容\n",
    "\n",
    "        需要提取的数据内容如下：\n",
    "        {text}\n",
    "\n",
    "        需要提前的数据项如下：\n",
    "        - name\n",
    "        - email\n",
    "        - experience (list of positions with title and company)\n",
    "        - skills (list of skills)\n",
    "        \"\"\"\n",
    "        messages = [{\"role\": \"user\", \"content\": prompt}]\n",
    "        response = call_llm(messages)\n",
    "        return response\n",
    "    def post(self, shared, prep_res, exec_res):\n",
    "        if prep_res is None or exec_res is None:\n",
    "            return None\n",
    "        shared[\"structure\"] = exec_res\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [],
   "source": [
    "text = \"\"\"\n",
    "# JOHN SMTIH\n",
    "\n",
    "**Email:** johnsmtih1983@gnail.com\n",
    "**Phone:** (555) 123-4556\n",
    "**Address:** 123 Main st, Anytown, USA\n",
    "\n",
    "## PROFFESIONAL SUMMARY\n",
    "\n",
    "Dedicated and hardworking professional with over 10 years of exprience in business manegement. Known for finding creatve solutions to complex problems and excelent communication skills. Seeking new opportunites to leverage my expertise in a dynamic environment.\n",
    "\n",
    "## WORK EXPERENCE\n",
    "\n",
    "### SALES MANAGER\n",
    "**ABC Corportaion** | Anytown, USA | June 2018 - Present\n",
    "- Oversee a team of 12 sales represenatives and achieve quarterly targets\n",
    "- Increased departmnet revenue by 24% in fiscal year 2019-2020\n",
    "- Implemneted new CRM system that improved efficiency by 15%\n",
    "- Collabarate with Marketing team on product launch campaigns\n",
    "- Developed training materials for new hiers\n",
    "\n",
    "### ASST. MANAGER\n",
    "**XYZ Industries** | Somewhere Else, USA | March 2015 - may 2018\n",
    "- Assisted the Regional Manager in daily operations and reporting\n",
    "- managed inventory and vendor relations\n",
    "- Trained and mentored junior staff members\n",
    "- Recieved \"Employee of the Month\" award 4 times\n",
    "\n",
    "### CUSTOMER SERVICE REPRESENTATIVE\n",
    "**Fast Solutions Inc** | Another City, USA | January 2010 - February 2015\n",
    "* Responded to customer inquiries via phone email, and in-person\n",
    "* Resolved customer complaints and escalated issues when necessary\n",
    "* Maintained a 95% customer satsfaction rating\n",
    "\n",
    "\n",
    "## EDUCATIONS\n",
    "\n",
    "**Bachelor of Buisness Administration**\n",
    "University of Somewhere | 2006 - 2010\n",
    "GPA: 3.6/4.0\n",
    "\n",
    "**Assosiate Degree in Communications**\n",
    "Community College | 2004-2006\n",
    "\n",
    "## SKILSS\n",
    "\n",
    "- Microsoft Office: *Excel, Word, Powerpoint* (Advanced)\n",
    "- Customer relationship management (CRM) software\n",
    "- Team leadership & managment\n",
    "- Project management\n",
    "- Public speking\n",
    "- Time managemant\n",
    "\n",
    "## REFERENCES\n",
    "\n",
    "Available upon reqeust\n",
    "\n",
    "### OTHER ACTVITIES\n",
    "- Volunteer at the local food bank (2016-present)\n",
    "- Member of Toastmasters International\n",
    "- Enjoy hiking and photografy\n",
    "\"\"\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [],
   "source": [
    "shared = {}\n",
    "shared[\"text\"] = text\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "```json\n",
      "{\n",
      "  \"name\": \"JOHN SMTIH\",\n",
      "  \"email\": \"johnsmtih1983@gnail.com\",\n",
      "  \"experience\": [\n",
      "    {\n",
      "      \"title\": \"SALES MANAGER\",\n",
      "      \"company\": \"ABC Corportaion\"\n",
      "    },\n",
      "    {\n",
      "      \"title\": \"ASST. MANAGER\",\n",
      "      \"company\": \"XYZ Industries\"\n",
      "    },\n",
      "    {\n",
      "      \"title\": \"CUSTOMER SERVICE REPRESENTATIVE\",\n",
      "      \"company\": \"Fast Solutions Inc\"\n",
      "    }\n",
      "  ],\n",
      "  \"skills\": [\n",
      "    \"Microsoft Office: Excel, Word, Powerpoint (Advanced)\",\n",
      "    \"Customer relationship management (CRM) software\",\n",
      "    \"Team leadership & managment\",\n",
      "    \"Project management\",\n",
      "    \"Public speking\",\n",
      "    \"Time managemant\"\n",
      "  ]\n",
      "}\n",
      "```\n"
     ]
    }
   ],
   "source": [
    "\n",
    "flow = Flow(start=structure_node())\n",
    "\n",
    "flow.run(shared)\n",
    "print(shared[\"structure\"])\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {},
   "outputs": [],
   "source": [
    "import json\n",
    "structure_content = json.loads(shared[\"structure\"].strip().split(\"```json\")[1].split(\"```\")[0])\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "dict_keys(['name', 'email', 'experience', 'skills'])"
      ]
     },
     "execution_count": 19,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "structure_content.keys()\n",
    "\n",
    "\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": ".venv",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.10.11"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
